#include <gtest/gtest.h>
#include "RangePartitionMatcherDemo.h"

TEST(test1_findPartitionByValue,SelectOne){
        std::vector<RangePartition<int> > partitions = {
        {"p0", 0, 10},
        {"p2", 20, 30},
        {"p1", 10, 20},
        {"invalid", 50, 40}, // should be skipped
        {"empty", 100, 100} // empty range
    };
    RangePartitionMatcherDemo matcher;
    matcher.initial(partitions);

    std::optional<std::string> res("p0");
    EXPECT_EQ(matcher.findPartitionByValue(8),res);
}

TEST(test1_findPartitionByRange,SelectRange){
        std::vector<RangePartition<int> > partitions = {
        {"p0", 0, 10},
        {"p2", 20, 30},
        {"p1", 10, 20},
        {"invalid", 50, 40}, // should be skipped
        {"empty", 100, 100} // empty range
    };
    RangePartitionMatcherDemo matcher;
    matcher.initial(partitions);

    std::vector<std::string> vstring = {"p0","p1"};
    EXPECT_EQ(matcher.findPartitionByRange(5,15),vstring);
}

TEST(test2_findPartitionByValue,ErrorOne){
        std::vector<RangePartition<int> > partitions = {
        {"p0", 0, 10},
        {"p2", 20, 30},
        {"p1", 10, 20},
        {"invalid", 50, 40}, // should be skipped
        {"empty", 100, 100} // empty range
    };
    RangePartitionMatcherDemo matcher;
    matcher.initial(partitions);

    std::optional<std::string> res(std::nullopt);
    EXPECT_EQ(matcher.findPartitionByValue(-1),res);
}

TEST(test2_findPartitionByRange,ErrorRange){
        std::vector<RangePartition<int> > partitions = {
        {"p0", 0, 10},
        {"p2", 20, 30},
        {"p1", 10, 20},
        {"invalid", 50, 40}, // should be skipped
        {"empty", 100, 100} // empty range
    };
    RangePartitionMatcherDemo matcher;
    matcher.initial(partitions);

    std::vector<std::string> vstring = {"InValid Range!"};
    EXPECT_EQ(matcher.findPartitionByRange(5,35),vstring);
}

TEST(test_otherSample,OneAndRange){
        std::vector<RangePartition<int> > partitions = {
        {"p0", -1000, 0},
        {"p2", 1000, 2000},
        {"p1", 0, 1000},
        {"p4", 3000, 4000},
        {"p3", 2000, 3000},
    };
    RangePartitionMatcherDemo matcher;
    matcher.initial(partitions);

    std::optional<std::string> res("p3");
    EXPECT_EQ(matcher.findPartitionByValue(2000),res);

    std::vector<std::string> vstring = {"p0","p1","p2"};
    EXPECT_EQ(matcher.findPartitionByRange(-999,1111),vstring);
}


int main(int argc,char** argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}